package com.example.company_project_fangyu.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.company_project_fangyu.demo.service.ReporterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.Part;
import java.io.IOException;
import java.util.Map;
/**
 * @author kalong
 * @date 2023/09/13
 */
@Slf4j
@RestController
public class ReporterController {
    @Autowired
    private ReporterService reporterService;
    @PostMapping("/msgPush")
    public void msgPush(@RequestBody JSONObject data) {
        log.info("msgPush eventId:{} abilityId: {}",
                data.getString("event_id"), data.getString("ability_id"));
        reporterService.saveMsg(data);
    }
    @PostMapping("/videoPush")
    public void pushVideo(@RequestParam Map<String, Part> map,
                          @RequestParam(name = "eventId") String eventId) throws IOException {
        log.info("videoPush eventId: {}", eventId);
        reporterService.handleVideo(eventId, map.get("file").getInputStream());
    }
}